package wonder.com.chinaerweima.Wedge;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.TextView;

import wonder.com.chinaerweima.R;

/**
 * Created by Administrator on 2016/6/15.
 */
public class CustomFontTextView extends TextView{
    private Context context;
    private String fontPath;
    public CustomFontTextView(Context context) {
        this(context,null);
    }

    public CustomFontTextView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public CustomFontTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context=context;
        getAttrs(attrs);
        setCustomFontInAssets(fontPath);
    }
    private void getAttrs(AttributeSet attributeSet){
      TypedArray ta= context.obtainStyledAttributes(attributeSet, R.styleable.CustomFontTextView);
      fontPath= ta.getString(R.styleable.CustomFontTextView_fontPathInAssets) ;
        ta.recycle();
    }
    private void setCustomFontInAssets(String fontPath){
        try {
            if (fontPath!=null)setTypeface(Typeface.createFromAsset(context.getAssets(),fontPath));
        }catch (Exception e){
            Log.e("wonder","你配置的路径有误在Assets目录中找不到"+fontPath);
        }
    }
}
